<template>
  <div class="app-container">
    <template>
      <div class="hidden-md-and-up">
        <el-alert title="如若不适应手机端操作，建议使用电脑操作" type="warning" />
      </div>
    </template>
    <div class="table-container">
      <div style="padding-bottom:20px; display: flex;">
        <div style="width: 260px;">
          <label>专利名称</label>
          <el-input v-model="search.patentName" size="medium" placeholder="输入专利名称" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>专利/软著号</label>
          <el-input v-model="search.patentNumber" size="medium" placeholder="输入专利/软著号" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>专利权人</label>
          <el-input v-model="search.patentee" size="medium" placeholder="请输入专利权人" style="width: 160px;" />
        </div>
        <div style="width: 260px;">
          <label>发明人</label>
          <el-input v-model="search.allAuthor" size="medium" placeholder="请输入发明人" style="width: 160px;" />
        </div>
      </div>
      <div style="padding-bottom:20px; display: flex;">
        <div style="width: 220px;">
          <label>专利状态</label>
          <el-select v-model="search.status" size="medium" placeholder="请选择" style="width: 160px;" @change="statusChange">
            <el-option label="全部" value="" />
            <el-option label="草稿" value="草稿" />
            <el-option label="待院级审核" value="待院级审核" />
            <el-option label="被院级退回" value="被院级退回" />
            <el-option label="待校级审核" value="待校级审核" />
            <el-option label="被校级退回" value="被校级退回" />
            <el-option label="审核通过" value="审核通过" />
          </el-select>
        </div>
        <div style="margin-left: 20px;" />
        <el-button type="success" size="medium" plain icon="el-icon-download" @click="excel_dialog = true">导出</el-button>
        <el-button type="primary" size="medium" plain @click="addthesis">专利录入</el-button>
      </div>
      <el-table
        v-loading="paperListLoading"
        :data="paperList"
        element-loading-text="Loading"
        border
        fit
        :summary-method="getSummaries"
        show-summary
      >
        <el-table-column type="selection" align="center" width="55" />
        <!-- <el-table-column align="center" label="序号" width="55">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column> -->
        <el-table-column align="center" label="专利名称" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.patentName }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="专利类型" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.patentCate }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="专利/软著号" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.patentNumber }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="专利权人" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.patentee }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="发明人" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.allAuthor }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="状态"
          min-width="70"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
            <el-tag v-if="scope.row.status === '被院级退回' || scope.row.status === '被校级退回'" type="warning">{{ scope.row.reason }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="分数" min-width="100">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.score }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="300">
          <template slot-scope="scope">
            <el-popover
              :ref="`popoverdelete-${scope.$index}`"
              placement="top"
              width="160"
            >
              <p>确认删除本行吗？该操作不可撤销</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="scope._self.$refs[`popoverdelete-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click="delete_thesis(scope.$index, scope.row)">确定</el-button>
              </div>
            </el-popover>
            <el-popover
              :ref="`popovercommit-${scope.$index}`"
              placement="top"
              width="160"
            >
              <p>确认提交吗？提交后不可再修改</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="scope._self.$refs[`popovercommit-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click="handleCommitConfirm(scope.$index, scope.row)">确定</el-button>
              </div>
            </el-popover>
            <!-- 撤回弹窗 -->
            <el-popover
              :ref="`popoverwithdraw-${scope.$index}`"
              placement="top"
              width="160"
            >
              <p>确认撤回专利吗？</p>
              <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="scope._self.$refs[`popoverwithdraw-${scope.$index}`].doClose()">取消</el-button>
                <el-button type="primary" size="mini" @click="handleWithdrawConfirm(scope.$index, scope.row)">确定</el-button>
              </div>
            </el-popover>
            <!-- <el-popover
              :ref="`popoveredit-${scope.$index}`"
              placement="top"
            >
              <div style="text-align: center; margin: 0">
                <el-button type="primary" size="mini" @click="open_thesis_info_dialog(scope.row)">专利信息</el-button>
                <el-button type="primary" size="mini" @click="open_thesis_author_dialog(scope.row)">作者列表</el-button>
                <el-button type="primary" size="mini" @click="open_thesis_project_dialog(scope.row)">相关项目</el-button>
                <el-button type="primary" size="mini">相关附件</el-button>
                <el-button type="primary" size="mini" @click="open_infoview_dialog(scope.row)">信息总览</el-button>
              </div>
            </el-popover> -->
            <el-button
              size="mini"
              @click="open_infoview_dialog(scope.row)"
            >
              编辑
            </el-button>
            <el-button
              v-popover="`popoverdelete-${scope.$index}`"
              size="mini"
              type="danger"
            >
              删除
            </el-button>
            <el-button
              v-popover="`popovercommit-${scope.$index}`"
              size="mini"
              type="success"
              :disabled="false"
            >
              提交
            </el-button>
            <el-button
              v-popover="`popoverwithdraw-${scope.$index}`"
              size="mini"
              type="info"
              :disabled="false"
            >
              撤回
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          background
          :current-page="p1_page"
          :page-sizes="[1,2,3,10, 20, 30, 40]"
          :page-size="p1_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="p1_total"
          @size-change="p1_sizechange"
          @current-change="p1_currentchange"
        />
        <!-- @size-change="handleSizeChange"
          @current-change="handleCurrentChange" -->
        <!-- 使用了size-change和current-change事件来处理页码大小和当前页变动时候触发的事件。 -->
      </div>
      <el-dialog title="专利录入" :visible.sync="thesis_add_dialog" width="75%" :close-on-click-modal="false">
        <el-form ref="thesis_add_form1" :model="thesis_add_form1" :rules="add_rules" label-position="top" label-width="160px" autocomplete="off">
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="录入人" prop="enteredName">
                <el-input v-model="thesis_add_form1.enteredName" :disabled="true" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="申请国家或地区" prop="applyCountry">
                <el-input v-model="thesis_add_form1.applyCountry" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="专利类型" prop="patentCate">
                <el-select v-model="thesis_add_form1.patentCate" placeholder="请选择专利类型" style="width: 270px;">
                  <el-option label="发明专利" value="发明专利" />
                  <el-option label="软件著作权" value="软件著作权" />
                  <el-option label="实用新型专利" value="实用新型专利" />
                  <el-option label="外观设计型专利" value="外观设计型专利" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="专利名称" prop="patentName">
                <el-input v-model="thesis_add_form1.patentName" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="专利/软著号" prop="patentNumber">
                <el-input v-model="thesis_add_form1.patentNumber" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="专利权人" prop="patentee">
                <el-input v-model="thesis_add_form1.patentee" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="授权日期" prop="authorizationDate">
                <el-date-picker
                  v-model="thesis_add_form1.authorizationDate"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="统计分类" prop="classifi">
                <el-select v-model="thesis_add_form1.classifi" placeholder="请选择专利分类" style="width: 270px;">
                  <el-option label="社科类" value="社科类" />
                  <el-option label="科技类" value="科技类" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="申报日期" prop="declarationDate">
                <el-date-picker
                  v-model="thesis_add_form1.declarationDate"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="录入日期" prop="enteredDate">
                <el-date-picker
                  v-model="thesis_add_form1.enteredDate"
                  type="datetime"
                  placeholder="选择日期时间"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="所属机构" prop="dept">
                <el-select
                  v-model="thesis_add_form1.dept"
                  :loading="deptLoading"
                  placeholder="请选择所属机构(可检索)"
                  filterable
                  clearable
                  @focus="fetchDeptData"
                >
                  <el-option v-for="item in dept_options" :key="item.deptID" :label="item.deptName" :value="item.deptID" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="终止日期" prop="endDate">
                <el-date-picker
                  v-model="thesis_add_form1.endDate"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="简介" prop="introduction">
                <el-input v-model="thesis_add_form1.introduction" placeholder="请选择收录情况" style="width: 270px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="法律状态" prop="legalState">
                <el-input v-model="thesis_add_form1.legalState" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="备注" prop="notes">
                <el-input v-model="thesis_add_form1.notes" type="textarea" autosize style="min-width: 270px; min-height:40px; width:300px;" />
              </el-form-item>
            </el-col>
            <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
              <br>
            </el-col>
            <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
              <el-form-item label="技术领域" prop="technology">
                <el-input v-model="thesis_add_form1.technology" style="min-width: 270px;" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-popover
            ref="dialog1"
            v-model="visible1"
            placement="top"
            width="160"
          >
            <p>关闭后，已填写的内容会丢失，建议保存为草稿，确定要关闭吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="visible1 = false">取消</el-button>
              <el-button type="primary" size="mini" @click="visible1 = false;thesis_add_dialog = false;">确定</el-button>
            </div>
          </el-popover>
          <el-button v-popover:dialog1>关 闭</el-button>
          <el-tooltip placement="top" effect="light">
            <div slot="content">检查表单是否填写正确<br>若不正确则最终无法提交审核</div>
            <el-button type="primary" plain @click="check_rules('thesis_add_form1')">检 查</el-button>
          </el-tooltip>
          <el-button type="primary" @click="save_add_form1(thesis_add_form1)">保 存</el-button>
        </div>
      </el-dialog>
      <el-dialog title="编辑信息" :visible.sync="infoview_dialog" width="75%">
        <el-collapse v-model="activeNames">
          <el-collapse-item name="1">
            <template slot="title">
              <div class="el-descriptions__title">专利信息</div>
            </template>
            <el-dialog title="专利信息" :visible.sync="thesis_info_dialog" width="60%" append-to-body :close-on-click-modal="false">
              <el-form ref="thesis_add_form2" :model="thesis_add_form2" :rules="add_rules" label-position="top" label-width="160px" autocomplete="off">
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="录入人" prop="enteredName">
                      <el-input v-model="thesis_add_form2.enteredName" :disabled="true" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="专利类型" prop="patentCate">
                      <el-select v-model="thesis_add_form2.patentCate" placeholder="请选择专利类型" style="width: 270px;">
                        <el-option label="发明专利" value="发明专利" />
                        <el-option label="软件著作权" value="软件著作权" />
                        <el-option label="实用新型专利" value="实用新型专利" />
                        <el-option label="外观设计型专利" value="外观设计型专利" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="专利名称" prop="patentName">
                      <el-input v-model="thesis_add_form2.patentName" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="专利/软著号" prop="patentNumber">
                      <el-input v-model="thesis_add_form2.patentNumber" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="专利权人" prop="patentee">
                      <el-input v-model="thesis_add_form2.patentee" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="所属机构" prop="deptName">
                      <el-select
                        v-model="thesis_add_form2.deptName"
                        :loading="deptLoading"
                        placeholder="请选择所属机构(可检索)"
                        filterable
                        clearable
                        value-key="dept"
                        @focus="fetchDeptData"
                      >
                        <el-option v-for="item in dept_options" :key="item.deptID" :label="item.deptName" :value="item.deptName" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="申请国家或地区" prop="applyCountry">
                      <el-input v-model="thesis_add_form2.applyCountry" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="授权日期" prop="authorizationDate">
                      <el-date-picker
                        v-model="thesis_add_form2.authorizationDate"
                        type="date"
                        placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="统计分类" prop="classifi">
                      <el-select v-model="thesis_add_form2.classifi" placeholder="请选择专利分类" style="width: 270px;">
                        <el-option label="科技类" value="科技类" />
                        <el-option label="社科类" value="社科类" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="申报日期" prop="declarationDate">
                      <el-date-picker
                        v-model="thesis_add_form2.declarationDate"
                        type="date"
                        placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="录入日期" prop="enteredDate">
                      <el-date-picker
                        v-model="thesis_add_form2.enteredDate"
                        type="datetime"
                        placeholder="选择日期时间"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="技术领域" prop="technology">
                      <el-input v-model="thesis_add_form2.technology" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="终止日期" prop="endDate">
                      <el-date-picker
                        v-model="thesis_add_form2.endDate"
                        type="date"
                        placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                      />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="简介" prop="introduction">
                      <el-input v-model="thesis_add_form2.introduction" placeholder="请选择收录情况" style="width: 270px;" />
                    </el-form-item>
                  </el-col>
                  <el-col :xs="1" :sm="1" :md="2" :lg="2" :xl="2">
                    <br>
                  </el-col>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="法律状态" prop="legalState">
                      <el-input v-model="thesis_add_form2.legalState" style="min-width: 270px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :xs="20" :sm="20" :md="20" :lg="10" :xl="8">
                    <el-form-item label="备注" prop="notes">
                      <el-input v-model="thesis_add_form2.notes" type="textarea" autosize style="min-width: 270px; min-height:40px; width:300px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-popover
                  ref="dialog2"
                  v-model="visible2"
                  placement="top"
                  width="160"
                >
                  <p>关闭后，已填写的内容会丢失，建议保存为草稿，确定要关闭吗？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="visible2 = false">取消</el-button>
                    <el-button type="primary" size="mini" @click="visible2 = false;thesis_info_dialog = false;">确定</el-button>
                  </div>
                </el-popover>
                <el-button v-popover:dialog2>关 闭</el-button>
                <el-tooltip placement="top" effect="light">
                  <div slot="content">检查表单是否填写正确<br>若不正确则最终无法提交审核</div>
                  <el-button type="primary" plain @click="check_rules('thesis_add_form2')">检 查</el-button>
                </el-tooltip>
                <el-button type="primary" @click="save_add_form2(thesis_add_form2)">保 存</el-button>
              </div>
            </el-dialog>
            <div style="padding-bottom:20px; display: flex;">
              <el-button type="primary" size="medium" plain @click="open_thesis_info_dialog(infoview1)">编辑信息</el-button>
            </div>
            <el-descriptions :column="2" size="medium" border :label-style="{width:'25%'}" :content-style="{width:'25%'}">
              <el-descriptions-item label="专利ID">
                {{ infoview1.patentID }}
              </el-descriptions-item>
              <el-descriptions-item label="录入人">
                {{ infoview1.enteredName }}
              </el-descriptions-item>
              <el-descriptions-item label="专利类型">
                {{ infoview1.patentCate }}
              </el-descriptions-item>
              <el-descriptions-item label="专利名称">
                {{ infoview1.patentName }}
              </el-descriptions-item>
              <el-descriptions-item label="专利权人">
                {{ infoview1.patentee }}
              </el-descriptions-item>
              <el-descriptions-item label="专利/软著号">
                {{ infoview1.patentNumber }}
              </el-descriptions-item>
              <el-descriptions-item label="申请国家或地区">
                {{ infoview1.applyCountry }}
              </el-descriptions-item>
              <el-descriptions-item label="授权日期">
                {{ infoview1.authorizationDate }}
              </el-descriptions-item>
              <el-descriptions-item label="统计分类">
                {{ infoview1.classifi }}
              </el-descriptions-item>
              <el-descriptions-item label="申报日期">
                {{ infoview1.declarationDate }}
              </el-descriptions-item>
              <el-descriptions-item label="所属机构">
                {{ infoview1.deptName }}
              </el-descriptions-item>
              <el-descriptions-item label="终止日期">
                {{ infoview1.endDate }}
              </el-descriptions-item>
              <el-descriptions-item label="录入日期">
                {{ infoview1.enteredDate }}
              </el-descriptions-item>
              <el-descriptions-item label="简介">
                {{ infoview1.introduction }}
              </el-descriptions-item>
              <el-descriptions-item label="法律状态">
                {{ infoview1.legalState }}
              </el-descriptions-item>
              <el-descriptions-item label="技术领域">
                {{ infoview1.technology }}
              </el-descriptions-item>
              <el-descriptions-item label="状态">
                <el-tag :type="infoview1.status | statusFilter">{{ infoview1.status }}</el-tag>
              </el-descriptions-item>
              <el-descriptions-item label="退回原因">
                {{ infoview1.reason }}
              </el-descriptions-item>
              <el-descriptions-item label="分数">
                <el-tag type="">{{ infoview1.score }}</el-tag>
              </el-descriptions-item>
              <el-descriptions-item label="备注">
                {{ infoview1.notes }}
              </el-descriptions-item>
            </el-descriptions>
          </el-collapse-item>
          <el-collapse-item name="2">
            <template slot="title">
              <div class="el-descriptions__title">
                <span style="color: red;">*</span>量化分数
              </div>
            </template>
            <div style="margin-bottom: 10px;">
              <span>分数计算规则参考：</span>
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/应用技术和专利成果计分规则可视化.pdf'" target="_blank">获奖计分规则可视化</el-link>
              <br>
              <span>官方文件：</span>
              <el-link type="primary" :href="$FILE_PATH+'/file/量化细则图/湖北师范大学科研工作量化管理办法（修订版）.pdf'" target="_blank">湖北师范大学科研工作量化管理办法（修订版）</el-link>
              <el-switch
                v-model="thesis_source_form.manualScoreMode"
                active-text="手动填分"
                inactive-text="自动计分"
                style="float: right; margin-right: 20px;"
                @change="handleScoreModeChange"
              />
            </div>
            <!-- 自动计分模式 -->
            <el-form v-if="!thesis_source_form.manualScoreMode" ref="thesis_source_form" :inline="true" :model="thesis_source_form" :rules="add_rules" label-width="80px" style="margin-left: 0;">
              <el-form-item label="选择类型" prop="source_cascader_value">
                <el-cascader
                  v-model="thesis_source_form.source_cascader_value"
                  :options="source_options"
                  :props="{ expandTrigger: 'hover' }"
                  filterable
                  clearable
                  :show-all-levels="true"
                  class="cascader"
                  @change="cascaderhandleChange"
                  @focus="fetchCascadingData"
                />
              </el-form-item>
              <el-form-item v-show="firstchoice" label="到账经费" prop="funds">
                <el-input v-model="thesis_source_form.funds" placeholder="单位(万元)" style="width: 100px;" />
              </el-form-item>
              <el-form-item v-show="showScInput" label="分数" prop="sc">
                <el-input v-model="thesis_source_form.sc" placeholder="请输入分数" style="width: 100px;" @input="updateFinalValue" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="addSource">提交</el-button>
              </el-form-item>
            </el-form>
            <!-- 手动填分模式 -->
            <el-form v-if="thesis_source_form.manualScoreMode" ref="thesis_source_form" :inline="true" :model="thesis_source_form" :rules="manual_source_rules" label-width="80px" style="margin-left: 0;">
              <el-form-item label="最终分数" prop="finalValue">
                <el-input v-model="thesis_source_form.finalValue" placeholder="请直接填入分数" style="width: 200px;" />
              </el-form-item>
              <el-form-item label="算分详情" prop="Note">
                <el-input
                  v-model="thesis_source_form.Note"
                  type="textarea"
                  :rows="3"
                  placeholder="请填入算分依据"
                  :maxlength="500"
                  show-word-limit
                  style="width: 700px; resize: vertical;"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="addSource">提交</el-button>
              </el-form-item>
            </el-form>
            <el-table
              v-loading="sourceListLoading"
              :data="sourceList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column v-if="!thesis_source_form.manualScoreMode" align="center" label="一级类型" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.patentType1 }}
                </template>
              </el-table-column>
              <el-table-column v-if="!thesis_source_form.manualScoreMode" align="center" label="二级类型" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.patentType2 }}
                </template>
              </el-table-column>
              <el-table-column v-if="!thesis_source_form.manualScoreMode" align="center" label="三级类型" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.patentType3 }}
                </template>
              </el-table-column>
              <el-table-column v-if="!thesis_source_form.manualScoreMode" align="center" label="到账经费" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.funds }}
                </template>
              </el-table-column>
              <el-table-column v-if="thesis_source_form.manualScoreMode" align="center" label="算分详情" min-width="200">
                <template slot-scope="scope">
                  {{ scope.row.Note }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="最终得分" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.finalValue }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="150">
                <template slot-scope="scope">
                  <el-popover
                    :ref="`popoverdelete-${scope.$index}`"
                    placement="top"
                    width="160"
                  >
                    <p>确认删除本行吗？该操作不可撤销</p>
                    <div style="text-align: right; margin: 0">
                      <el-button size="mini" type="text" @click="scope._self.$refs[`popoverdelete-${scope.$index}`].doClose()">取消</el-button>
                      <el-button type="primary" size="mini" @click="delete_thesis_source(scope.$index, scope.row)">确定</el-button>
                    </div>
                  </el-popover>
                  <el-button
                    v-popover="`popoverdelete-${scope.$index}`"
                    size="mini"
                    type="danger"
                  >
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="3">
            <template slot="title">
              <div class="el-descriptions__title">
                <span style="color: red;">*</span>发明人信息
              </div>
            </template>
            <el-dialog width="60%" :title="innerdialog1_title" :visible.sync="thesis_author_innerdialog" append-to-body :close-on-click-modal="false">
              <author-search :target-form="thesis_author_form" style="margin-left: 10px;" @author-selected="handleAuthorSelected" />
              <el-tabs v-model="thesis_author_form_activeName" stretch>
                <el-tab-pane v-if="innerdialog1_add || thesis_author_form_activeName === 'first'" label="校内教师" name="first" />
                <el-tab-pane v-if="innerdialog1_add || thesis_author_form_activeName === 'second'" label="校外作者" name="second" />
                <el-tab-pane v-if="innerdialog1_add || thesis_author_form_activeName === 'third'" label="学生" name="third" />
              </el-tabs>
              <el-form ref="thesis_author_form" :model="thesis_author_form" :rules="author_rules" label-position="top" label-width="160px" style="margin-top: 20px;">
                <el-form-item v-if="thesis_author_form_activeName === 'first'" label="工号" prop="userAccount">
                  <el-autocomplete
                    v-model="thesis_author_form.userAccount"
                    :fetch-suggestions="querySearchAsync"
                    placeholder="请输入工号搜索"
                    :trigger-on-focus="false"
                    @select="authorHandleSelect"
                  />
                </el-form-item>
                <el-form-item label="姓名" prop="name">
                  <el-input
                    v-model="thesis_author_form.name"
                    :placeholder="thesis_author_form_activeName === 'first' ? '仅支持通过工号搜索填充' : '请输入姓名'"
                    :disabled="thesis_author_form_activeName === 'first'"
                  />
                </el-form-item>
                <el-form-item label="所属机构" prop="dept">
                  <el-input
                    v-model="thesis_author_form.dept"
                    :placeholder="thesis_author_form_activeName === 'first' ? '仅支持通过工号搜索填充' : '请输入所属机构'"
                    :disabled="thesis_author_form_activeName === 'first'"
                  />
                </el-form-item>
                <el-form-item label="作者排名" prop="ranking">
                  <el-select v-model="thesis_author_form.ranking" placeholder="请选择">
                    <el-option
                      v-for="n in 10"
                      :key="n"
                      :label="n.toString()"
                      :value="n.toString()"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="考核系数（应在0-100之间）" prop="assessment">
                  <el-input v-model="thesis_author_form.assessment" />
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="thesis_author_innerdialog = false">取 消</el-button>
                <el-button v-if="innerdialog1_add" type="primary" @click="add_thesis_author">确 定</el-button>
                <el-button v-if="!innerdialog1_add" type="primary" @click="edit_thesis_author">确 定</el-button>
              </div>
            </el-dialog>
            <div style="padding-bottom:20px; display: flex;">
              <el-button type="primary" size="medium" plain @click="open_add_author_innerdialog">添加发明人</el-button>
            </div>
            <el-table
              v-loading="paperAuthorListLoading"
              :data="paperAuthorList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column align="center" label="工号" min-width="100">
                <template slot-scope="scope">
                  {{ (scope.row.peopleType === '校内教师' || !scope.row.peopleType) && scope.row.userAccount ? scope.row.userAccount : '无' }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="姓名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.name }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="所属院系" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.dept }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="发明人类型" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.peopleType }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="考核系数" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.assessment }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="个人得分" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.pscore }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="150">
                <template slot-scope="scope">
                  <el-popover
                    :ref="`popoverdelete-${scope.$index}`"
                    placement="top"
                    width="160"
                  >
                    <p>确认删除本行吗？该操作不可撤销</p>
                    <div style="text-align: right; margin: 0">
                      <el-button size="mini" type="text" @click="scope._self.$refs[`popoverdelete-${scope.$index}`].doClose()">取消</el-button>
                      <el-button type="primary" size="mini" @click="delete_thesis_author(scope.$index, scope.row)">确定</el-button>
                    </div>
                  </el-popover>
                  <el-button
                    size="mini"
                    @click="open_edit_author_innerdialog(scope.$index, scope.row)"
                  >
                    编辑
                  </el-button>
                  <el-button
                    v-popover="`popoverdelete-${scope.$index}`"
                    size="mini"
                    type="danger"
                  >
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="4">
            <template slot="title">
              <div class="el-descriptions__title">相关项目</div>
            </template>
            <el-dialog width="60%" :title="innerdialog2_title" :visible.sync="thesis_project_innerdialog" append-to-body :close-on-click-modal="false">
              <el-form ref="thesis_project_form" :model="thesis_project_form" :rules="add_rules" label-position="top" label-width="160px">
                <el-form-item label="项目名称" prop="projectName">
                  <el-input v-model="thesis_project_form.projectName" />
                </el-form-item>
                <el-form-item label="项目负责人" prop="head">
                  <el-input v-model="thesis_project_form.head" :disabled="true" />
                </el-form-item>
                <el-form-item label="署名单位" prop="signedUnit">
                  <el-select v-model="thesis_project_form.signedUnit" placeholder="请选择">
                    <el-option label="第一署名" value="第一署名" />
                    <el-option label="第二署名" value="第二署名" />
                    <el-option label="第三署名" value="第三署名" />
                    <el-option label="其他署名" value="其他署名" />
                  </el-select>
                </el-form-item>
                <el-form-item label="开始日期" prop="startTime">
                  <el-date-picker
                    v-model="thesis_project_form.startTime"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy 年 MM 月 dd 日"
                    value-format="yyyy-MM-dd"
                  />
                </el-form-item>
                <el-form-item label="结束日期" prop="endTime">
                  <el-date-picker
                    v-model="thesis_project_form.endTime"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy 年 MM 月 dd 日"
                    value-format="yyyy-MM-dd"
                  />
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="thesis_project_innerdialog = false">取 消</el-button>
                <el-button v-if="innerdialog2_add" type="primary" @click="add_thesis_project">确 定</el-button>
                <el-button v-if="!innerdialog2_add" type="primary" @click="edit_thesis_project">确 定</el-button>
              </div>
            </el-dialog>
            <div style="padding-bottom:20px; display: flex;">
              <el-button type="primary" size="medium" plain @click="open_add_project_innerdialog">添加相关项目</el-button>
            </div>
            <el-table
              v-loading="paperProjectListLoading"
              :data="paperProjectList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="selection" align="center" width="55" />
              <el-table-column align="center" label="项目名称" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.projectName }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="项目负责人" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.head }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="署名单位" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.signedUnit }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="开始日期" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.startTime }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="结束日期" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.endTime }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="150">
                <template slot-scope="scope">
                  <el-popover
                    :ref="`popoverdelete-${scope.$index}`"
                    placement="top"
                    width="160"
                  >
                    <p>确认删除本行吗？该操作不可撤销</p>
                    <div style="text-align: right; margin: 0">
                      <el-button size="mini" type="text" @click="scope._self.$refs[`popoverdelete-${scope.$index}`].doClose()">取消</el-button>
                      <el-button type="primary" size="mini" @click="delete_thesis_project(scope.$index, scope.row)">确定</el-button>
                    </div>
                  </el-popover>
                  <el-button
                    size="mini"
                    @click="open_edit_project_innerdialog(scope.$index, scope.row)"
                  >
                    编辑
                  </el-button>
                  <el-button
                    v-popover="`popoverdelete-${scope.$index}`"
                    size="mini"
                    type="danger"
                  >
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="5">
            <template slot="title">
              <div class="el-descriptions__title">
                <span style="color: red;">*</span>附件信息</div>
            </template>
            <div class="upload">
              <div class="uploadBox">
                <!-- <el-upload
                  ref="upload"
                  class="upload-demo"
                  drag
                  action="http://218.197.18.189:9528/fileUpload/fileUpload"
                  action="http://218.197.18.189:9528/fileUpload/fileUpload"
                  accept=".jpg,.png,.doc,.docx,.xls,.xlsx,.pdf"
                  :on-success="handleFileSuccess"
                  :show-file-list="true"
                >
                  <i class="el-icon-upload" />
                  <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                  <div slot="tip" class="el-upload__tip">只能上传jpg/png/doc/xls/pdf/docx/xlsx文件，且不超过50MB</div>
                </el-upload> -->
                <el-upload
                  ref="upload"
                  class="upload-demo"
                  drag
                  :action="$BACK_PATH+'/fileUpload/uploadfileAchievementFile'"
                  accept=".jpg,.png,.doc,.docx,.xls,.xlsx,.pdf"
                  :on-success="handleFileSuccess"
                  :before-upload="beforeFileUpload"
                  :disabled="infoview1.status === '待院级审核' || infoview1.status === '待校级审核' || infoview1.status === '审核通过'"
                  :show-file-list="true"
                  :headers="{ 'X-Token': $store.getters.token }"
                  multiple
                  @click.native="handleUploadClick"
                >
                  <i class="el-icon-upload" />
                  <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                  <div slot="tip" class="el-upload__tip">只能上传jpg/png/doc/xls/pdf/docx/xlsx文件，且不超过50MB</div>
                </el-upload>
              </div>
              <div class="uploadText">
                <el-alert
                  title="注意事项"
                  type="warning"
                  :closable="false"
                  :show-icon="true"
                >
                  <p>1、一次上传一个文件，上传完成的文件会在下方表格中显示</p>
                  <p>2、在下方表格中您可以进行下载和删除操作</p>
                  <p>3、本模块您需要上传的附件有“XXXXX”、“XXXXXX”</p>
                  <p>4、高质量论文必须上传论文和检索报告等</p>
                </el-alert>
              </div>
            </div>
            <el-table
              v-loading="fileListLoading"
              :data="fileList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" width="55" />
              <el-table-column align="left" label="文件名称" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.filename }}
                </template>
              </el-table-column>
              <el-table-column align="left" label="文件大小" min-width="150">
                <template slot-scope="scope">
                  <span v-if="scope.row.filesize / 1024 / 1024 < 1">{{ (scope.row.filesize / 1024).toFixed(2) + 'KB' }}</span>
                  <span v-else>{{ (scope.row.filesize / 1024 / 1024).toFixed(2) + 'MB' }}</span>
                </template>
              </el-table-column>
              <el-table-column align="left" label="上传时间" min-width="150">
                <template slot-scope="scope">
                  {{ scope.row.filedate }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="150">
                <template slot-scope="scope">
                  <el-popover
                    :ref="`popoverdelete-${scope.$index}`"
                    placement="top"
                    width="160"
                  >
                    <p>确认删除本行吗？该操作不可撤销</p>
                    <div style="text-align: right; margin: 0">
                      <el-button size="mini" type="text" @click="scope._self.$refs[`popoverdelete-${scope.$index}`].doClose()">取消</el-button>
                      <el-button type="primary" size="mini" @click="deleteFile(scope.$index, scope.row)">确定</el-button>
                    </div>
                  </el-popover>
                  <el-button
                    size="mini"
                    @click="downloadFile(scope.row)"
                  >
                    下载
                  </el-button>
                  <el-button
                    v-popover="`popoverdelete-${scope.$index}`"
                    size="mini"
                    type="danger"
                  >
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
          <el-collapse-item name="6">
            <template slot="title">
              <div class="el-descriptions__title">审核记录</div>
            </template>
            <el-table
              v-loading="paperAuditListLoading"
              :data="paperAuditList"
              element-loading-text="Loading"
              border
              fit
            >
              <el-table-column type="index" align="center" label="序号" width="55" />
              <el-table-column align="center" label="审核员职位" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerRole }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核员姓名" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerName }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="项目状态变化" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.statusChange }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核意见" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditOpinion }}
                </template>
              </el-table-column>
              <el-table-column align="center" label="审核时间" min-width="100">
                <template slot-scope="scope">
                  {{ scope.row.auditerTime }}
                </template>
              </el-table-column>
            </el-table>
          </el-collapse-item>
        </el-collapse>
        <div slot="footer" class="dialog-footer">
          <el-button @click="infoview_dialog = false">关 闭</el-button>
        </div>
      </el-dialog>
      <el-dialog title="导出excel" :visible.sync="excel_dialog" width="60%">
        <el-alert
          title="请选择需要导出的数据"
          type="success"
          description="选择的数据为表头，未选择的数据将不会导出"
          :closable="false"
        />
        <div style="margin: 15px;">
          <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
          <div style="margin: 15px 0;" />
          <el-checkbox-group v-model="check_fields" @change="handleCheckedFieldsChange">
            <el-checkbox v-for="field in fields_list" :key="field" :label="field">{{ field }}</el-checkbox>
          </el-checkbox-group>
        </div>
        <!-- <el-alert
          title="请选择时间范围"
          type="success"
          description="选择导出数据的时间范围"
          :closable="false"
        /> -->
        <div slot="footer" class="dialog-footer">
          <el-button @click="excel_dialog = false">关 闭</el-button>
          <download-excel
            style="display:inline-block !important;margin-left:10px;"
            :data="EXCEL.DetailsForm"
            :fields="EXCEL.json_fields"
            :header="EXCEL.title"
            type="xls"
            name="专利数据导出.xls"
            :fetch="createExportData"
            :before-generate="startDownload"
            :before-finish="finishDownload"
          >
            <!-- 上面可以自定义自己的样式，还可以引用其他组件button -->
            <el-button type="success" plain>确认导出</el-button>
          </download-excel>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { GetPatentDTOById, getMyPaperList, getUserPatents, thesis_add, thesis_add2, thesis_delete, thesis_commit, thesis_withdraw, get_thesis_author, thesis_author_add, thesis_author_delete, thesis_author_edit, get_thesis_project, thesis_project_add, thesis_project_delete, thesis_project_edit, file_add, get_file, file_delete, getCascadingData, addQulification, getQulification, deleteQulification } from '@/api/patent'
import { get_thesis_Audit } from '@/api/audit'
import { getUserByAccount } from '@/api/user'
import { Message, Loading } from 'element-ui'
import { getDepts } from '@/api/system'
import { mapGetters } from 'vuex'
import AuthorSearch from '@/components/AuthorSearch'

export default {
  name: 'ThesisView',
  components: {
    AuthorSearch
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        草稿: 'info',
        待院级审核: '',
        被院级退回: 'danger',
        待校级审核: '',
        被校级退回: 'danger',
        审核通过: 'success'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      deptLoading: false,
      deptMap: {}, // 部门名称到ID的映射
      dept_options: [],
      search: {
        allAuthor: '',
        patentName: '',
        patentNumber: '',
        patentee: '',
        status: ''
      },
      status: '',
      thesis_add_dialog: false,
      thesis_info_dialog: false,
      // thesis_author_dialog: false,
      // thesis_project_dialog: false,
      thesis_author_innerdialog: false,
      thesis_project_innerdialog: false,
      infoview_dialog: false,
      visible1: false,
      visible2: false,
      thesis_add_form1: {
        allAuthor: '',
        allAuthorName: '',
        annex: '',
        applyCountry: '',
        associatedProjects: '',
        authorizationDate: '',
        classifi: '',
        declarationDate: '',
        dept: '',
        deptName: '',
        endDate: '',
        entered: '',
        enteredName: '',
        enteredDate: '',
        introduction: '',
        legalState: '',
        notes: '',
        organization: '',
        patentCate: '',
        patentID: '',
        patentName: '',
        patentNumber: '',
        patentee: '',
        reason: '',
        status: '',
        technology: ''
      },
      thesis_add_form2: {
        allAuthor: '',
        allAuthorName: '',
        annex: '',
        applyCountry: '',
        associatedProjects: '',
        authorizationDate: '',
        classifi: '',
        declarationDate: '',
        dept: '',
        deptName: '',
        endDate: '',
        entered: '',
        enteredName: '',
        enteredDate: '',
        introduction: '',
        legalState: '',
        notes: '',
        organization: '',
        patentCate: '',
        patentID: '',
        patentName: '',
        patentNumber: '',
        patentee: '',
        reason: '',
        status: '',
        technology: ''
      },
      add_rules: {
        entered: [],
        deptName: [
          { required: true, message: '所属机构名称不能为空', trigger: 'blur' }
        ],
        dept: [
          { required: true, message: '所属机构不能为空', trigger: 'blur' }
        ],
        patentCate: [
          { required: true, message: '专利类别不能为空', trigger: 'blur' }
        ],
        patentName: [
          { required: true, message: '专利名称不能为空', trigger: 'blur' }
        ],
        patentNumber: [
          { required: true, message: '专利/软著号不能为空', trigger: 'blur' }
        ],
        patentee: [
          { required: true, message: '专利权人不能为空', trigger: 'blur' }
        ],
        applyCountry: [],
        authorizationDate: [
          { required: true, message: '授权日期不能为空', trigger: 'blur' }
        ],
        classifi: [
          { required: true, message: '统计分类不能为空', trigger: 'blur' }
        ],
        declarationDate: [
          { required: true, message: '申请日期不能为空', trigger: 'blur' }
        ],
        enteredDate: [],
        endDate: [],
        introduction: [],
        legalState: [],
        notes: [],
        technology: []
      },
      thesis_author_form: {
        assessment: '',
        authortype: '',
        dept: '',
        name: '',
        // patentAuthorID: '',
        patentID: '',
        userAccount: '',
        peopleType: '校内教师'
      },
      thesis_author_form_activeName: 'first',
      author_rules: {
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        userAccount: [
          { required: true, message: '工号不能为空', trigger: 'blur' }
        ],
        dept: [
          { required: true, message: '所属机构不能为空', trigger: 'blur' }
        ],
        authortype: [
          { required: true, message: '发明人类型不能为空', trigger: 'change' }
        ],
        assessment: [
          { required: true, message: '考核系数不能为空', trigger: 'blur' },
          {
            pattern: /^([1-9]\d*|0)(\.\d{1,2})?$/,
            message: '请输入有效数字',
            trigger: ['blur', 'change']
          }
        ]
      },
      thesis_project_form: {
        campusID: '',
        endTime: '',
        head: '',
        patentID: '',
        patentProjectID: '',
        projectID: '',
        projectName: '',
        signedUnit: '',
        startTime: ''
      },
      paperList: null,
      paperListLoading: false,
      tableSum: {
        score: 0
      },
      p1_size: 10,
      p1_total: 0,
      p1_page: 1,
      paperAuthorList: null,
      paperAuthorListLoading: false,
      innerdialog1_title: '新增发明人',
      innerdialog1_add: true,
      paperProjectList: null,
      paperProjectListLoading: false,
      innerdialog2_title: '新增相关项目',
      innerdialog2_add: true,
      paperAuditList: [],
      paperAuditListLoading: false,
      committedButtons: {}, // 存储已提交状态的按钮
      infoview1: {
        allAuthor: '',
        allAuthorName: '',
        annex: '',
        applyCountry: '',
        associatedProjects: '',
        authorizationDate: '',
        classifi: '',
        declarationDate: '',
        dept: '',
        deptName: '',
        endDate: '',
        entered: '',
        enteredName: '',
        enteredNameDate: '',
        introduction: '',
        legalState: '',
        notes: '',
        organization: '',
        patentCate: '',
        patentID: '',
        patentName: '',
        patentNumber: '',
        patentee: '',
        reason: '',
        status: '',
        technology: ''
      },
      activeNames: ['1', '2', '3', '4', '5', '6'],
      excel_dialog: false,
      all_fields: {
        '所有发明人':	'allAuthor',
        '申请国家或地区':	'applyCountry',
        '关联项目':	'associatedProjects',
        '授权日期':	'authorizationDate',
        '统计分类':	'classifi',
        '申报日期':	'declarationDate',
        '终止日期':	'endDate',
        '录入人':	'entered',
        '录入日期':	'enteredDate',
        '简介':	'introduction',
        '法律状态':	'legalState',
        '备注':	'note',
        '所属机构':	'dept',
        '专利类型':	'patentCate',
        '专利ID':	'patentID',
        '专利名称':	'patentName',
        '专利/软著号':	'patentNumber',
        '专利权人':	'patentee',
        '未通过原因':	'reason',
        '审核状态':	'status',
        '技术领域':	'technology'
      },
      fields_list: [
        '所有发明人',
        '申请国家或地区',
        '关联项目',
        '授权日期',
        '统计分类',
        '申报日期',
        '终止日期',
        '录入人',
        '录入日期',
        '简介',
        '法律状态',
        '备注',
        '所属机构',
        '专利类型',
        '专利ID',
        '专利名称',
        '专利/软著号',
        '专利权人',
        '未通过原因',
        '审核状态',
        '技术领域'
      ],
      check_fields: [],
      checkAll: false,
      isIndeterminate: false,
      EXCEL: {
        title: '测试表格',
        json_fields: null,
        DetailsForm: null
      },
      fileList: [],
      fileListLoading: false,
      fileForm: {
        patentid: '',
        filedate: '',
        fileid: '',
        filename: '',
        filesize: '',
        fileurl: ''
      },
      source_options: [],
      firstchoice: false,
      showScInput: false,
      sourceCascaderLoading: null,
      sourceListLoading: false,
      sourceList: [],
      thesis_source_form: {
        manualScoreMode: false,
        source_cascader_value: [],
        funds: '',
        patentID: '',
        patentQualificationID: '',
        patentType1: '',
        patentType2: '',
        patentType3: '',
        finalValue: '',
        type1ID: '',
        type2ID: '',
        type3ID: '',
        sc: '',
        Note: ''
      },
      source_rules: {
        source_cascader_value: [
          { required: true, message: '请选择类型', trigger: 'blur' }
        ],
        finalValue: [
          { required: true, message: '分数不能为空', trigger: 'blur' }
        ],
        Note: [
          { required: true, message: '算分详情不能为空', trigger: 'blur' }
        ]
      },
      // 手动填分模式的验证规则
      manual_source_rules: {
        finalValue: [
          { required: true, message: '分数不能为空', trigger: 'blur' }
        ],
        Note: [
          { required: true, message: '算分详情不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'uid',
      'roles',
      'name',
      'dept'
    ]),
    MyPaperPost() {
      return {
        pageNum: this.p1_page,
        pageSize: this.p1_size,
        ...this.search
      }
    }
  },
  watch: {
    thesis_author_form_activeName(newVal) {
      // 只在新增模式下清空表单，编辑模式保留数据
      if (this.innerdialog1_add) {
        this.resetForm('thesis_author_form')
        this.thesis_author_form.userAccount = ''
      }
      if (newVal === 'first') {
        this.thesis_author_form.peopleType = '校内教师'
      } else if (newVal === 'second') {
        this.thesis_author_form.peopleType = '校外作者'
      } else {
        this.thesis_author_form.peopleType = '学生'
      }
    },
    search: {
      handler() {
        this.paperListLoading = true
        clearTimeout(this.searchTimeout)
        this.searchTimeout = setTimeout(() => {
          this.fetchPaperData()
          this.paperListLoading = false
        }, 1000)
      },
      deep: true // 启用深度监视，可监听对象内部属性变化
    }
  },
  created() {
    this.fetchPaperData()
  },
  methods: {
    handleAuthorSelected(author) {
      // 可以在这里处理选中作者后的额外逻辑
      console.log('选中的作者:', author)
    },
    // 处理切换模式
    handleScoreModeChange(value) {
      this.thesis_source_form.manualScoreMode = value
      this.thesis_source_form.type1ID = ''
      this.thesis_source_form.type2ID = ''
      this.thesis_source_form.type3ID = ''
      this.thesis_source_form.Note = ''
      this.thesis_source_form.finalValue = 0
    },
    fetchDeptData() {
      if (this.dept_options.length === 0) {
        this.deptLoading = true
        getDepts().then(response => {
          if (response.code === 200) {
            this.dept_options = response.data
            if (Object.keys(this.deptMap).length === 0) {
              this.deptMap = response.data.reduce((map, dept) => {
                map[dept.deptName] = dept.deptID
                return map
              }, {})
            }
            this.deptLoading = false
          }
        })
      }
    },
    fetchPaperData() {
      this.paperListLoading = true
      getUserPatents(this.MyPaperPost).then(response => {
        if (response.code === 200) {
          this.paperList = response.data.list
          this.p1_total = response.data.total
          this.tableSum.score = response.data.figure
          this.paperListLoading = false

          // 初始化已提交状态
          this.committedButtons = {}
          this.paperList.forEach(item => {
            // 根据状态判断是否已提交
            if (item.status === '待院级审核' || item.status === '待校级审核' || item.status === '审核通过' || item.status === '被院级退回' || item.status === '被校级退回') {
              this.committedButtons[item.patentID] = true
            } else {
              this.committedButtons[item.patentID] = false
            }
          })
        }
      })
    },
    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        if (column.label === '分数') {
          sums[index] = <el-tag>{this.tableSum.score}分</el-tag>
          return
        }
      })
      return sums
    },
    statusChange() {
      this.fetchPaperData()
    },
    deptChange() {
      this.fetchPaperData()
    },
    p1_sizechange(newsize) {
      this.p1_size = newsize
      this.p1_page = 1
      this.fetchPaperData()
    },
    p1_currentchange(newpage) {
      this.p1_page = newpage
      this.fetchPaperData()
    },
    filterTag(value, row) {
      return row.status === value
    },
    resetForm(formName) {
      if (this.$refs[formName] !== undefined) {
        this.$refs[formName].resetFields()
        // 如果是重置量化分数表单，同时重置SC相关状态
        if (formName === 'thesis_source_form') {
          this.showScInput = false
          this.firstchoice = false
        }
      }
    },
    check_rules(formName) {
      // 只校验必填项
      const form = this.$refs[formName]
      if (!form) {
        Message.error('表单引用不存在')
        return
      }

      try {
        form.validate((valid, invalidFields) => {
          // 处理验证结果
          if (valid) {
            Message.success('表单填写正确！')
          } else {
            const errorFields = []
            const detailedErrorMessages = []

            Object.keys(invalidFields).forEach(fieldName => {
              errorFields.push(fieldName)
              const fieldErrors = invalidFields[fieldName]
              if (fieldErrors && fieldErrors.length > 0) {
                fieldErrors.forEach(error => {
                  if (error.message) {
                    detailedErrorMessages.push(error.message)
                  }
                })
              }
            })

            // 显示错误信息
            if (detailedErrorMessages.length > 0) {
              Message.error(detailedErrorMessages[0])
            } else if (errorFields.length > 0) {
              const displayFields = errorFields.slice(0, 5)
              const moreCount = errorFields.length - displayFields.length
              let errorMsg = `请检查以下字段: ${displayFields.join('、')}`
              if (moreCount > 0) {
                errorMsg += ` 等${moreCount}个字段`
              }
              Message.error(errorMsg)
            } else {
              Message.error('请填写完整信息')
            }
          }
        })
      } catch (error) {
        Message.error('表单验证过程中发生错误')
      }
    },
    addthesis() {
      this.thesis_add_dialog = true
      this.resetForm('thesis_add_form1')
      this.thesis_add_form1.enteredName = this.name
    },
    save_add_form1(formdata) {
      // 修复：获取并显示第一个错误信息
      this.$refs.thesis_add_form1.validate((valid, invalidFields) => {
        if (valid) {
          formdata.entered = this.uid
          thesis_add(formdata).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_add_dialog = false
              this.fetchPaperData()
            }
          })
        } else {
          // 获取第一个错误并显示
          for (const field in invalidFields) {
            if (invalidFields[field] && invalidFields[field].length > 0) {
              Message.error(invalidFields[field][0].message)
              return false
            }
          }
          Message.error('表单数据有误，请检查')
          return false
        }
      })
    },
    open_thesis_info_dialog(data) {
      this.thesis_info_dialog = true
      this.resetForm('thesis_add_form2')
      this.thesis_add_form2 = JSON.parse(JSON.stringify(data))
    },
    save_add_form2(formdata) {
      // 修复：获取并显示第一个错误信息
      this.$refs.thesis_add_form2.validate((valid, invalidFields) => {
        if (valid) {
          formdata.dept = this.deptMap[formdata.deptName]
          thesis_add2(formdata).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_info_dialog = false
              this.fetchPaperData()
              this.fetchOneData()
            }
          })
        } else {
          // 获取第一个错误并显示
          for (const field in invalidFields) {
            if (invalidFields[field] && invalidFields[field].length > 0) {
              Message.error(invalidFields[field][0].message)
              return false
            }
          }
          Message.error('表单数据有误，请检查')
          return false
        }
      })
    },
    delete_thesis(index, row) {
      this.$refs[`popoverdelete-${index}`].doClose()
      thesis_delete(row.patentID).then(response => {
        if (response.code === 200) {
          Message.success('删除成功')
          this.fetchPaperData()
        }
      })
    },
    commit_thesis(index, row) {
      // 提交前先重新加载附件列表，确保fileList包含最新的附件数据
      this.fileForm.patentid = row.patentID
      this.fetchFileData().then(() => {
        // 等待附件列表加载完成后再检查
        if (this.fileList.length === 0) {
          this.$message.error('请上传附件')
          return
        }
        thesis_commit(row.patentID).then(response => {
          console.log('提交API响应:', response)
          if (response && response.code === 200) {
            this.$message.success('提交成功')
            this.$set(this.committedButtons, row.patentID, true)
            this.fetchPaperData()
          } else {
            console.error('提交失败，非200响应:', response)
            this.$message.error('提交失败，请稍后重试')
          }
        })
      })
    },
    handleCommitConfirm(index, row) {
      // 先关闭弹窗
      this.$refs[`popovercommit-${index}`].doClose()
      // 然后调用提交方法
      this.commit_thesis(index, row)
    },
    handleWithdrawConfirm(index, row) {
      // 先关闭弹窗
      this.$refs[`popoverwithdraw-${index}`].doClose()
      // 然后调用撤回方法
      this.withdraw_thesis(index, row)
    },
    withdraw_thesis(index, row) {
      thesis_withdraw(row.patentID).then(response => {
        console.log('撤回API响应:', response)
        if (response && response.code === 200) {
          this.$message.success('撤回成功')
          this.$set(this.committedButtons, row.patentID, false)
          this.fetchPaperData()
        } else {
          console.error('撤回失败，非200响应:', response)
          this.$message.error('撤回失败，请稍后重试')
        }
      })
    },
    fetch_thesis_author() {
      this.paperAuthorListLoading = true
      get_thesis_author(this.thesis_author_form.patentID).then(response => {
        if (response.code === 200) {
          this.paperAuthorList = response.data
          this.paperAuthorListLoading = false
          console.log(response.data)
        }
      })
    },
    open_thesis_author_dialog(row) {
      this.thesis_author_dialog = true
      this.thesis_author_form.patentID = row.patentID
      this.fetch_thesis_author()
    },
    open_thesis_author_innerdialog() {
      this.thesis_author_innerdialog = true
      this.resetForm('thesis_author_form')
    },
    open_add_author_innerdialog() {
      // 先设置新增模式标志，确保 watch 能正确判断
      this.innerdialog1_add = true
      this.innerdialog1_title = '新增成员列表'
      // 重置到校内教师标签页
      this.thesis_author_form_activeName = 'first'
      this.open_thesis_author_innerdialog()
    },
    open_edit_author_innerdialog(index, row) {
      // 先设置标签页，确保正确的字段能够渲染
      if (row.peopleType === '校内教师') {
        this.thesis_author_form_activeName = 'first'
      } else if (row.peopleType === '校外作者') {
        this.thesis_author_form_activeName = 'second'
      } else if (row.peopleType === '学生') {
        this.thesis_author_form_activeName = 'third'
      } else {
        // 默认显示校内教师
        this.thesis_author_form_activeName = 'first'
      }
      // 再设置对话框状态和标题
      this.innerdialog1_title = '编辑作者'
      this.innerdialog1_add = false
      this.thesis_author_innerdialog = true

      // 使用 $nextTick 确保标签页和字段已渲染后再赋值
      this.$nextTick(() => {
        this.thesis_author_form = JSON.parse(JSON.stringify(row))
        // 清除验证状态
        if (this.$refs.thesis_author_form) {
          this.$refs.thesis_author_form.clearValidate()
        }
      })
    },
    querySearchAsync(queryString, cb) {
      getUserByAccount(queryString).then(response => {
        if (response.code === 200) {
          var results = []
          response.data.forEach(item => {
            const value = JSON.parse(
              JSON.stringify(item).replace(/account/g, 'value')
            )
            results.push(value)
          })
          clearTimeout(this.timeout)
          this.timeout = setTimeout(() => {
            cb(results)
          }, 3000 * Math.random())
        }
      })
    },
    authorHandleSelect(item) {
      this.thesis_author_form.name = item.name
      this.thesis_author_form.dept = item.dept
    },
    add_thesis_author() {
      this.$refs.thesis_author_form.validate(valid => {
        if (valid) {
          // 将作者类型从peopleType复制到authortype，确保表格正确显示作者类型
          this.thesis_author_form.authortype = this.thesis_author_form.peopleType
          thesis_author_add(this.thesis_author_form).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_author_innerdialog = false
              this.fetchOneData()
              this.fetch_thesis_author()
            }
          })
        } else {
          Message.error('请填写完整信息')
          return false
        }
      })
    },
    edit_thesis_author() {
      this.$refs.thesis_author_form.validate(valid => {
        if (valid) {
          // 将作者类型从peopleType复制到authortype，确保表格正确显示作者类型
          this.thesis_author_form.authortype = this.thesis_author_form.peopleType
          thesis_author_edit(this.thesis_author_form).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_author_innerdialog = false
              this.fetchOneData()
              this.fetch_thesis_author()
            }
          })
        } else {
          Message.error('请填写完整信息')
          return false
        }
      })
    },
    delete_thesis_author(index, row) {
      this.$refs[`popoverdelete-${index}`].doClose()
      thesis_author_delete(row.patentAuthorID).then(response => {
        if (response.code === 200) {
          Message.success('删除成功')
          this.fetch_thesis_author()
        }
      })
    },
    fetch_thesis_project() {
      this.paperProjectListLoading = true
      get_thesis_project(this.thesis_project_form.patentID).then(response => {
        if (response.code === 200) {
          this.paperProjectList = response.data
          this.paperProjectListLoading = false
          console.log(response.data)
        }
      })
    },
    open_thesis_project_dialog(row) {
      this.thesis_project_dialog = true
      this.thesis_project_form.patentID = row.patentID
      this.fetch_thesis_project()
    },
    open_thesis_project_innerdialog() {
      this.thesis_project_innerdialog = true
      this.resetForm('thesis_project_form')
    },
    open_add_project_innerdialog() {
      this.open_thesis_project_innerdialog()
      this.innerdialog2_title = '新增相关项目'
      this.innerdialog2_add = true
    },
    open_edit_project_innerdialog(index, row) {
      this.open_thesis_project_innerdialog()
      this.innerdialog2_title = '编辑相关项目'
      this.thesis_project_form = JSON.parse(JSON.stringify(row))
      this.innerdialog2_add = false
    },
    add_thesis_project() {
      this.$refs.thesis_project_form.validate(valid => {
        if (valid) {
          console.log(this.thesis_project_form)
          thesis_project_add(this.thesis_project_form).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_project_innerdialog = false
              this.fetch_thesis_project()
            }
          })
        } else {
          Message.error('请填写完整信息')
          return false
        }
      })
    },
    edit_thesis_project() {
      this.$refs.thesis_project_form.validate(valid => {
        if (valid) {
          thesis_project_edit(this.thesis_project_form).then(response => {
            if (response.code === 200) {
              Message.success('保存成功')
              this.thesis_project_innerdialog = false
              this.fetch_thesis_project()
            }
          })
        } else {
          Message.error('请填写完整信息')
          return false
        }
      })
    },
    delete_thesis_project(index, row) {
      this.$refs[`popoverdelete-${index}`].doClose()
      thesis_project_delete(row.patentProjectID).then(response => {
        if (response.code === 200) {
          Message.success('删除成功')
          this.fetch_thesis_project()
        }
      })
    },
    fetch_thesis_Audit() {
      this.paperAuditListLoading = true
      get_thesis_Audit(this.infoview1.patentID).then(response => {
        if (response.code === 200) {
          this.paperAuditList = response.data
          this.paperAuditListLoading = false
        }
      })
    },
    fetchOneData() {
      GetPatentDTOById(this.infoview1.patentID).then(response => {
        if (response.code === 200) {
          this.infoview1 = response.data
        }
      })
    },
    open_infoview_dialog(row) {
      this.infoview_dialog = true
      this.infoview1.patentID = row.patentID
      this.fetchOneData()
      this.thesis_author_form.patentID = row.patentID
      this.fetch_thesis_author()
      this.thesis_project_form.patentID = row.patentID
      this.fetch_thesis_project()
      this.fileForm.patentid = row.patentID
      this.fetchFileData()
      this.resetForm('thesis_source_form')
      this.thesis_source_form.patentID = row.patentID
      this.fetchSourceData()
      this.fetch_thesis_Audit()
    },
    // 以下为数据导出
    handleCheckAllChange(val) {
      this.check_fields = val ? this.fields_list : []
      this.isIndeterminate = false
      this.EXCEL.json_fields = JSON.parse(JSON.stringify(this.all_fields, this.check_fields))
    },
    handleCheckedFieldsChange(value) {
      const checkedCount = value.length
      this.checkAll = checkedCount === this.fields_list.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.fields_list.length
      this.EXCEL.json_fields = JSON.parse(JSON.stringify(this.all_fields, this.check_fields))
    },
    async createExportData() {
      return await getMyPaperList(this.MyPaperPost).then(response => {
        if (response.code === 200) {
          if (response.data.list.length === 0) {
            Message.warning('返回数据为空，导出失败！')
            this.loadingInstance.close()
          }
          return response.data.list
        }
      })
    },
    startDownload() {
      this.excel_dialog = false
      this.loadingInstance = Loading.service({ text: '正在导出...' })
    },
    finishDownload() {
      setTimeout(() => {
        this.loadingInstance.close()
      }, 1000)
    },
    // 以下是附件上传
    handleUploadClick() {
      if (this.infoview1.status === '待院级审核' || this.infoview1.status === '待校级审核' || this.infoview1.status === '审核通过') {
        this.$message.error('当前状态不可上传')
      }
    },
    beforeFileUpload(file) {
      if (this.infoview1.status === '待院级审核' || this.infoview1.status === '待校级审核' || this.infoview1.status === '审核通过') {
        this.$message.error('当前状态不可上传')
        return false
      }
      return true
    },
    handleFileSuccess(res, file, fileList) {
      this.fileForm.filename = file.name
      this.fileForm.filesize = file.size
      // 处理文件URL，确保正确存储相对路径
      let fileUrl = res.data
      if (fileUrl.startsWith(this.$FILE_PATH)) {
        // 去除 FILE_PATH 前缀，保留相对路径
        fileUrl = fileUrl.replace(this.$FILE_PATH, '')
      }
      // 确保路径以 / 开头
      if (!fileUrl.startsWith('/')) {
        fileUrl = '/' + fileUrl
      }
      this.fileForm.fileurl = fileUrl
      this.commit_file()
    },
    commit_file() {
      file_add(this.fileForm).then(response => {
        if (response.code === 200) {
          Message.success('上传成功')
          this.fetchFileData()
        }
      })
    },
    fetchFileData() {
      this.fileListLoading = true
      return get_file(this.fileForm.patentid).then(response => {
        if (response.code === 200) {
          this.fileList = response.data
          this.fileListLoading = false
        }
        return response
      })
    },
    downloadFile(row) {
      var a = document.createElement('a')
      var event = new MouseEvent('click')
      // 确保文件路径正确拼接，处理fileupload文件夹的路径
      let fileUrl = row.fileurl
      if (!fileUrl.startsWith('https')) {
        // 如果不是完整URL，则拼接FILE_PATH
        if (fileUrl.startsWith('/')) {
          fileUrl = this.$FILE_PATH + fileUrl
        } else {
          fileUrl = this.$FILE_PATH + '/' + fileUrl
        }
      }
      a.href = fileUrl
      a.target = '_blank'
      console.log(row.fileurl)
      a.dispatchEvent(event)
    },
    deleteFile(index, row) {
      this.$refs[`popoverdelete-${index}`].doClose()
      file_delete(row.fileid).then(response => {
        if (response.code === 200) {
          Message.success('删除成功')
          this.fetchFileData()
        }
      })
    },
    // 以下是分数量化
    fetchSourceData() {
      this.sourceListLoading = true
      getQulification(this.thesis_source_form.patentID).then(response => {
        if (response.code === 200) {
          this.sourceList = response.data
          this.sourceListLoading = false
          this.thesis_source_form.manualScoreMode = response.data[0].manualScoreMode === 'true'
        }
      })
    },
    fetchCascadingData() {
      if (this.source_options.length === 0) {
        const options = {
          target: '.el-cascader__dropdown', // 类名
          lock: true,
          text: '拼命加载中...'
        }
        this.$nextTick(() => {
          this.sourceCascaderLoading = this.$loading(options)
          getCascadingData().then(response => {
            if (response.code === 200) {
              this.source_options = response.data
              this.sourceCascaderLoading.close()
            }
          })
          setTimeout(() => {
            this.sourceCascaderLoading.close()
          }, 10000)
        })
      }
    },
    cascaderhandleChange() {
      if (this.thesis_source_form.source_cascader_value[0] === 3 | this.thesis_source_form.source_cascader_value[0] === 4) {
        this.firstchoice = true
        this.thesis_source_form.funds = ''
      } else {
        this.firstchoice = false
        this.thesis_source_form.funds = ''
      }
      // 检查是否选择了国际专利（一级标题选择2之后的第三个二级标题）
      if (this.thesis_source_form.source_cascader_value.length >= 2 &&
          this.thesis_source_form.source_cascader_value[0] === 2 &&
          this.thesis_source_form.source_cascader_value[1] === 26) {
        this.showScInput = true
        // 如果已经输入了SC值，则将其赋给finalValue
        if (this.thesis_source_form.sc) {
          this.$set(this.thesis_source_form, 'finalValue', this.thesis_source_form.sc)
        }
      } else {
        this.showScInput = false
        this.thesis_source_form.sc = ''
      }
      if (this.thesis_source_form.source_cascader_value.length === 1) {
        this.thesis_source_form.type1ID = this.thesis_source_form.source_cascader_value[0]
        this.thesis_source_form.type2ID = 0
        this.thesis_source_form.type3ID = 0
      }
      if (this.thesis_source_form.source_cascader_value.length === 2) {
        this.thesis_source_form.type1ID = this.thesis_source_form.source_cascader_value[0]
        this.thesis_source_form.type2ID = this.thesis_source_form.source_cascader_value[1]
        this.thesis_source_form.type3ID = 0
      }
      if (this.thesis_source_form.source_cascader_value.length === 3) {
        this.thesis_source_form.type1ID = this.thesis_source_form.source_cascader_value[0]
        this.thesis_source_form.type2ID = this.thesis_source_form.source_cascader_value[1]
        this.thesis_source_form.type3ID = this.thesis_source_form.source_cascader_value[2]
      }
    },
    updateFinalValue() {
      // 当SC值变化时，自动更新finalValue
      if (this.showScInput && this.thesis_source_form.sc) {
        this.thesis_source_form.finalValue = this.thesis_source_form.sc
      }
    },
    addSource() {
      this.$refs.thesis_source_form.validate(valid => {
        if (valid) {
          // 提交前将 sc 值赋给 finalValue
          if (this.showScInput && this.thesis_source_form.sc) {
            this.thesis_source_form.finalValue = this.thesis_source_form.sc
          }
          addQulification(this.thesis_source_form).then(response => {
            if (response.code === 200) {
              Message.success('添加成功')
              this.fetchSourceData()
              this.fetchOneData()
              this.fetch_thesis_author()
            }
          })
        } else {
          if (this.thesis_source_form.manualScoreMode) {
            Message.error('请填写完整信息')
          } else {
            Message.error('请选择类型')
          }
          return false
        }
      })
    },
    delete_thesis_source(index, row) {
      this.$refs[`popoverdelete-${index}`].doClose()
      deleteQulification(row.patentQualificationID).then(response => {
        if (response.code === 200) {
          Message.success('删除成功')
          this.fetchSourceData()
          this.fetchOneData()
          this.fetch_thesis_author()
        }
      })
    }
  }
}
</script>

<style lang="scss">
.el-form{
  margin-left: 40px;
  .el-input,.el-select{
    width: 300px;
  }
}
.el-tag + .el-tag {
  margin: 10px 10px;
}
.margin-top {
  margin-top: 50px;
}
@media screen and (max-width:600px) {
  .el-dialog{
    width: 100% !important;
  }
  .el-form{
    margin-left: 25px;
  }
}
.el-cascader__dropdown {
  position: fixed !important;
}
  </style>

<style lang="scss" scoped>
    /* 确保所有表格操作列按钮横向排列 */
    /* 全局表格居中样式 - 最高优先级 */
    ::v-deep .el-table {
      /* 表头居中 */
      th {
        text-align: center !important;
        & > .cell {
          text-align: center !important;
        }
      }
      /* 数据行居中 */
      td {
        text-align: center !important;
        & > .cell {
          text-align: center !important;
          display: flex !important;
          justify-content: center !important;
          align-items: center !important;
        }
      }
      /* 确保所有内容居中 */
      .cell {
        text-align: center !important;
      }
      /* 合计行居中 */
      .el-table__footer-wrapper {
        td {
          text-align: center !important;
          & > .cell {
            text-align: center !important;
          }
        }
      }
      /* 修复可能的样式冲突 */
      .el-table__header-wrapper,
      .el-table__body-wrapper,
      .el-table__footer-wrapper {
        th,
        td {
          text-align: center !important;
          .cell {
            text-align: center !important;
          }
        }
      }
    }
    /* 1. 通用表格单元格样式 - 增强优先级 */
    ::v-deep .el-table td.el-table-column__cell {
      white-space: normal !important;
      overflow: hidden !important;
      min-width: 80px;
      text-align: center !important;
      word-break: break-all;
    }
    /* 2. 按钮样式 - 适用于所有表格中的按钮 */
    ::v-deep .el-table__row .el-button {
      display: inline-block !important;
      margin-right: 8px !important;
      margin-bottom: 0 !important;
      vertical-align: middle !important;
      float: none !important;
      position: static !important;
    }
    /* 3. 操作列容器样式 - 增强优先级 */
    ::v-deep .el-table-column__cell .cell {
      white-space: normal !important;
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      word-break: break-all;
      display: flex !important;
      flex-direction: row !important;
      flex-wrap: wrap !important;
      align-items: center !important;
      justify-content: center !important;
      min-width: 80px;
    }
    /* 4. 特别针对操作列的样式 - 增强选择器 */
    ::v-deep .el-table-column--action .cell,
    ::v-deep .el-table__row td:last-child .cell {
      display: flex !important;
      flex-direction: row !important;
      flex-wrap: nowrap !important;
      justify-content: center !important;
      align-items: center !important;
      white-space: nowrap !important;
      overflow: visible !important;
    }
    /* 5. 确保按钮不换行 - 增强选择器 */
    ::v-deep .el-table__row > td:not(:last-child) > .cell {
      white-space: normal !important;
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      word-break: break-all;
      display: block !important;
      text-align: center !important;
    }
    /* 6. 针对操作按钮组的额外样式 - 只针对最后一列操作列 */
    ::v-deep .el-table__body-wrapper .el-table__body .el-button-group,
    ::v-deep .el-table__body-wrapper .el-table__body .el-table__row td:last-child .cell > * {
      display: inline-flex !important;
      flex-direction: row !important;
      flex-wrap: nowrap !important;
    }
    /* 7. 确保表格行不被压缩 */
    ::v-deep .el-table__body {
      .el-table__row {
        td {
          min-width: 80px;
          height: auto;
          vertical-align: middle;
        }
      }
    }
    ::v-deep .cascader .el-input,::v-deep .cascader .el-select {
      width: 300px !important;
    }
</style>
